#include "CubeDoubleParam.h"

CubeDoubleParam::CubeDoubleParam()
:Param() { 
	values = NULL;
	size = 0;
	label = 0;
}

CubeDoubleParam::CubeDoubleParam( int tab, char tabLabel, const char *name )
:Param( name ) {
	this->size = tab;
	this->label = tabLabel;
	this->values = new MatrixDoubleParam[tab];
	this->ready = true;
}

CubeDoubleParam::CubeDoubleParam( int tab, int row, char tabLabel, char rowLabel, const char *name )
:Param( name ) {
	this->size = tab;
	this->label = tabLabel;
	this->values = new MatrixDoubleParam[tab];
	for (int i = 0; i < tab; i++)
		values[i] = MatrixDoubleParam(row, rowLabel, name);

	this->ready = true;
}

CubeDoubleParam::CubeDoubleParam( int tab, int row, int col, char tabLabel, char rowLabel, char colLabel, const char *name )
:Param( name ) {
	this->size = tab;
	this->label = tabLabel;
	this->values = new MatrixDoubleParam[tab];
	for (int i = 0; i < tab; i++)
		values[i] = MatrixDoubleParam(row, col, rowLabel, colLabel, name);

	this->ready = true;
}

CubeDoubleParam::CubeDoubleParam( CubeDoubleParam &src )
:Param( src ) {
	this->size = src.size;
	this->label = src.label;
	this->values = Util::copyArray<MatrixDoubleParam> (src.values, size);
	this->ready = src.ready;
}

CubeDoubleParam::~CubeDoubleParam() {
	delete [] values;
}

void CubeDoubleParam::read( Input &input ) throw (NotReady) {
	if (!ready) throwNotReady();
	for (int i = 0; i < size; i++)
		values[i].read(input);
}

MatrixDoubleParam &CubeDoubleParam::get( int i ) throw (InvalidIndex, NotReady) {
	if (!ready) throwNotReady();
	if (i < 0 || i >= size)
		throw new InvalidIndex( &label, 0, size-1, i );

	return values[i];
}

MatrixDoubleParam &CubeDoubleParam::operator [] ( int i ) throw (InvalidIndex, NotReady) {
	return get(i);
}

void CubeDoubleParam::setSize( int size ) throw (NotReady) {
	if (!ready) throwNotReady();

	MatrixDoubleParam *sub = new MatrixDoubleParam[size];
	for (int i = 0; i < size && i < this->size; i++)
		sub[i] = values[i];

	delete [] values;
	this->values = sub;
	this->size = size;
}

void CubeDoubleParam::setLabel( char label ) throw (NotReady) {
	if (!ready) throwNotReady();

	this->label = label;
}

int CubeDoubleParam::getSize() throw (NotReady) {
	if (!ready) throwNotReady();

	return size;
}

char CubeDoubleParam::getLabel() throw (NotReady) {
	if (!ready) throwNotReady();

	return label;
}